<HTML>
<HEAD>
<TITLE>Admin</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="../css/css.css" rel=stylesheet>
<script type='text/javascript' src="../js/jquery.js" charset="gb2312"></script>
<script type='text/javascript' src="../js/islogin.js" charset="gb2312"></script>
<?php
include('../../inc/global.inc');
include("../islogin.php");
$url = "http://www.sandib2b.cn/";
$name2 = "会员登录页广告";
if($_POST['submit'])
{
		$file = $_FILES['file'];
		$url2 = $_POST['url'];
		//print_r($file);
		/*name=>原始文件名,type=>文件类型,tmp_name=>临时文件地址,error=>错误0表示成功,size=>尺寸 单位k  1024k=1kb ,*/
		extract($file);
		$hz = pathinfo($name);
		$hzm =  strtolower($hz['extension']);//文件后缀名 不带.
		//echo $hzm;exit;
		if(!in_array($hzm,array('jpg','gif','bmp','png')))
		{
			 echo "<script>alert('请上传正确的文件类型。');history.go(-1);</script>";
			 exit;	
		}
		if($size>2048*1024)
		{
			 echo "<script>alert('文件大小为2048kb。');history.go(-1);</script>";
			 exit;
		}
		$newpath = PHPCMS_ROOT.'img/login/'.date('Ymdhis',time()).time().'.'.$hzm;
		$newpathurl = 'img/login/'.date('Ymdhis',time()).time().'.'.$hzm;
		if(move_uploaded_file($tmp_name,$newpath))
		{
			$result = mysql_query("UPDATE `sd_setting` SET `name`='".$name2."',`url`='".$url2."',`thumb`='".$url.$newpathurl."' where typeid =1",$conn);
			//mysql_query("INSERT INTO `sd_setting` (`id`, `name`, `thumb`, `typeid`) VALUES (NULL, '".$name2."', '".$url.$newpathurl."', '1')",$conn);
			//echo $result;exit;
			echo "<script>alert('上传成功！');</script>";
			
		}
}
$query = mysql_query('select * from `sd_setting` where 1 limit 1');
$rs = mysql_fetch_array($query);
//print_r($rs);
?>
</HEAD>
<BODY>
<center>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form action="" method="post" enctype="multipart/form-data" name="name" id="name" onSubmit="return check();">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bordercolor="#666666" bordercolorlight="#FFFFFF">
  <tr>
    <td width="14%" height="30">&nbsp;</td>
    <td width="86%" height="30">会员登录页广告</td>
  </tr>
  <tr>
    <td height="30" align="right">上传图片:</td>
    <td height="30"><input type="file" name="file" id="fuMain"></td>
  </tr>
  <tr>
    <td height="30" align="right">连接地址:</td>
    <td height="30"><input type="text" name="url" value="<?php echo $rs['url'];?>" size="50"></td>
  </tr>
  <tr>
    <td height="30">&nbsp;</td>
    <td height="30"><input name="submit" type="submit" id="submit" value="提交"></td>
  </tr>
  <tr>
    <td height="30">&nbsp;</td>
    <td height="30"><p>当前图片显示图</p>
      <p><img src="<?php echo $rs['thumb'];?>" width="200" height="100"/></p></td>
  </tr>
</table>
</form> 
</center>
</BODY>
</HTML>
<script>
function check()
{

	var obj=$('#fuMain').val();
     if(obj=='')
	 {
		alert('请选择要上传的文件');
		return false;
	 }
}
</script>
